#!/bin/bash
#file:	mysqlimptodb.sh

imptodb(){
workspace=$2
db=$3
table=$4

echo "workspace: $workspace"
echo "db: $db"
echo "table:$table"

cd $workspace

echo "gzip -d..."
gzip -d *.gz
for file in `ls *.log`;do
echo "imping $workspace/$file ..."
sed -i 's/\( \)\+/ /g' $file

mysql $db <<_EOF_
LOAD DATA INFILE '`echo $workspace/$file`' INTO TABLE `echo $table` FIELDS OPTIONALLY ENCLOSED BY '"' TERMINATED BY ' ' LINES TERMINATED BY '' IGNORE 6 LINES;
_EOF_

done
echo "gzip ...."
gzip *.log

}

cat $1 | while read LINE;
do
if [[  !( $LINE =~ ^# ) ]] ; then
imptodb $LINE
fi
done

